# Huawei Technologies Co.,Ltd.

set(ASYNC_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/async.txt)
set(ASYNC_BIN ${CMAKE_CURRENT_BINARY_DIR}/async.abc)
set(ASYNC_JS ${CMAKE_CURRENT_SOURCE_DIR}/async.js)
set(ASYNC_VERIFY ${CMAKE_CURRENT_SOURCE_DIR}/verify.sh)

set(RUNTIME_ARGUMENTS --boot-panda-files=${PANDA_BINARY_ROOT}/pandastdlib/arkstdlib.abc --load-runtimes=\"ecmascript\" --compiler-enable-jit=false ${ASYNC_BIN} _GLOBAL::func_main_0)

add_custom_command(
    OUTPUT ${ASYNC_OUTPUT}
    COMMENT "running javascript async testcase"
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:es2panda> ${ASYNC_JS} --output ${ASYNC_BIN}
    COMMAND rm -f ${ASYNC_OUTPUT}
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:ark> ${RUNTIME_ARGUMENTS} 2>&1 > ${ASYNC_OUTPUT}
    COMMAND bash ${ASYNC_VERIFY} ${ASYNC_OUTPUT}
)
add_custom_target(async
    DEPENDS ${ASYNC_OUTPUT} ${ASYNC_VERIFY}
)
add_dependencies(async ark_asm ark)
add_dependencies(ecmascript_common_tests async)
